package com.cf.work;

import com.cf.utils.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * 消息提供者
 *
 * @author Chengfei
 * @date 2020/8/29 14:27
 */
public class Produce {

    static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws Exception {

        //2. 连接对象
        Connection connection = ConnectionUtil.getConnection();
        //3.创建频道
        Channel channel = connection.createChannel();
        /**
         * queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments)
         * 4.创建队列
         * param1 队列名称
         * param2 是否可持久化
         * param3 是否独占该连接
         * param4 是否自动删除
         * param5 其他参数
         */

        channel.queueDeclare(QUEUE_NAME,true,false,false,null);

        for (int i = 0; i <= 30; i++) {
            // 发送信息
            String message = "你好；小兔子！work模式--" + i;

            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
        }

        System.out.println("发送消息成功!!!");
        //6 关闭资源
        channel.close();
        connection.close();

    }
}
